function conveterParamsToJson(paramsAndValues) {
    var jsonObj = {};

    var param = paramsAndValues.split("&");
    for ( var i = 0; param != null && i < param.length; i++) {
        var para = param[i].split("=");
        jsonObj[para[0]] = para[1];
    }

    return jsonObj;
}
/**
 * 日期转为周几
 * @param datetime
 * @returns {string}
 */
function dateToStr(datetime) {
    var year = datetime.getFullYear();
    var month = datetime.getMonth() + 1;//js从0开始取
    var date = datetime.getDate();
    var hour = datetime.getHours();
    var minutes = datetime.getMinutes();
    var second = datetime.getSeconds();
    if (month < 10) {
        month = "0" + month;
    }
    if (date < 10) {
        date = "0" + date;
    }
    if (hour < 10) {
        hour = "0" + hour;
    }
    if (minutes < 10) {
        minutes = "0" + minutes;
    }
    if (second < 10) {
        second = "0" + second;
    }

    var time = year + "-" + month + "-" + date + " " + hour + ":" + minutes + ":" + second;
    return time;
}

/**
 * 得到下周的日期
 * @param day 传入1为周一，传入6为周六
 * @returns {string}
 */
function getNextWeek(day){
    const dateOfToday = Date.now();
    const dayOfToday = (new Date().getDay() + 7 - 1) % 7;
    const daysOfThisWeek = Array.from(new Array(7))
        .map((_, i) => {
            const date = new Date(dateOfToday + (i+7 - dayOfToday) * 1000 * 60 * 60 * 24 )
            return date.getFullYear() +
                '-' +
                String(date.getMonth() + 1).padStart(2, '0') +
                '-' +
                String(date.getDate()).padStart(2, '0')
        });
    console.info(daysOfThisWeek);
    return daysOfThisWeek[day-1];
}

/**
 * 将表单数据封装为json
 * @param form
 * @returns
 */
function getFormData(form) {
    var formValues = $("#" + form).serialize();

    //关于jquery的serialize方法转换空格为+号的解决方法
    formValues = formValues.replace(/\+/g," ");   // g表示对整个字符串中符合条件的都进行替换
    var temp =  decodeURIComponent(JSON.stringify(conveterParamsToJson(formValues)));
    var queryParam = JSON.parse(temp);
    return queryParam;
}

/**
 得到地址栏的参数
 */
function getQueryString(name){
    var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
    var r = window.location.search.substr(1).match(reg);
    if(r!=null)return  unescape(r[2]); return null;
}